package com.study.testSpringBoot.config;

import com.study.testSpringBoot.login.MyLocalResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.study.testSpringBoot.interceptor.TestInterceptor;

@Configuration
public class CommonConfig implements WebMvcConfigurer {
	
	/**
	 * 第二种方式，需要在TestInterceptor类上加@Component注解，将拦截器注入进来
	 */
//	@Autowired
//	private TestInterceptor testInterceptor;

	/**
	 * 注入拦截器，第一中方式
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//第一种通过new直接注入
		registry.addInterceptor(new TestInterceptor()).addPathPatterns("/**");//拦截所有请求
		//第二种，通过@Autowired方式注入
//		registry.addInterceptor(testInterceptor).addPathPatterns("/**");//拦截所有请求
	}

}
